package linkedList;

import po.ListNode;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 二进制链表转整数1290.java
 * @Description TODO https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/
 * @createTime 2021年03月19日 19:11:00
 */
public class 二进制链表转整数1290 extends BaseLinkedListTest {
    public static int getDecimalValue(ListNode head) {
        if (head.next == null) {
            return head.val;
        }
        int number = 0;
        while (head != null) {
            number = (number << 1) + head.val;
            head = head.next;
        }
        return number;
    }

    public static void main(String[] args) {
        System.out.println(getDecimalValue(createLinkedList(1, 0, 1)));
    }
}
